package tools

import (
	"fmt"

	. "github.com/ahmetb/go-linq/v3"
)

type SliceOpera[T comparable] []T

func (s SliceOpera[T]) UniqueOpera() SliceOpera[T] {
	var (
		m           = map[T]struct{}{}
		uniqueArray = make([]T, 0, len(m))
	)
	for _, item := range s {
		if _, exist := m[item]; exist {
			continue
		}
		uniqueArray = append(uniqueArray, item)
		m[item] = struct{}{}
	}
	return uniqueArray
}

type Car struct {
	year         int
	owner, model string
}

var cars = []Car{
	{
		year:  10,
		owner: "1",
		model: "1",
	},
}

func Exec() {
	var owners []string

	From(cars).WhereT(func(c Car) bool {
		return c.year >= 2015
	}).SelectT(func(c Car) string {
		return c.owner
	}).ToSlice(&owners)

	fmt.Println(owners)
}
